<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>上报数据详情详情</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="基本信息" lselected="true">
            <form id="formSet1">
                <div class="fieldset1 tabel_col clearFix">
                    <div class="caption">
                        <span class="title">用户信息</span>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">客户姓名</div>
                        <div class="field">
                            <span name="userName" id="userName">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">用户手机号</div>
                        <div class="field">
                            <span name="userPhone" id="userPhone">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">法人代表</div>
                        <div class="field">
                            <span name="userLawPerson" id="userLawPerson">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">注册资金</div>
                        <div class="field">
                            <span name="userFund" id="userFund">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">注册省份</div>
                        <div class="field">
                            <span name="userProvince" id="userProvince">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">注册地址</div>
                        <div class="field">
                            <span name="userAddress" id="userAddress">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">企业注册时间</div>
                        <div class="field">
                            <span name="registerDate" id="registerDate">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">金融局入库结果</div>
                        <div class="field">
                            <span name="userInfoAsynCode" id="userInfoAsynCode">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">上报批次号</div>
                        <div class="field">
                            <span name="userInfoBatchNum" id="userInfoBatchNum">&nbsp;</span>
                        </div>
                    </div>

                    <div class="caption">
                        <span class="title">业务信息</span>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">担保类型</div>
                        <div class="field">
                            <span name="guaranteeType" id="guaranteeType">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">融资用途</div>
                        <div class="field">
                            <span name="financePurpose" id="financePurpose">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">担保开始日期</div>
                        <div class="field">
                            <span name="startTime" id="startTime">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">担保到期日期</div>
                        <div class="field">
                            <span name="endTime" id="endTime">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">担保费率</div>
                        <div class="field">
                            <span name="guaranteeRate" id="guaranteeRate">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">分担比例</div>
                        <div class="field">
                            <span name="shareProportion" id="shareProportion">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">是否农户</div>
                        <div class="field">
                            <span name="isAgriculture" id="isAgriculture">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">是否为中型企业</div>
                        <div class="field">
                            <span name="isMediumCompany" id="isMediumCompany">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">是否为小微企业</div>
                        <div class="field">
                            <span name="isTinyCompany" id="isTinyCompany">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">是否为综合服务贷款担保</div>
                        <div class="field">
                            <span name="isCompositeGuarantees" id="isCompositeGuarantees">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">是否为住房置业贷款担保</div>
                        <div class="field">
                            <span name="isHouseGuarantees" id="isHouseGuarantees">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">是否为互联网借贷担保</div>
                        <div class="field">
                            <span name="isInternetGuarantees" id="isInternetGuarantees">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">是否为银行业金融机构表外业务担保</div>
                        <div class="field">
                            <span name="isBankFinance" id="isBankFinance">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">被担保人是否为首次获得金融担保</div>
                        <div class="field">
                            <span name="passiveIsFirst" id="passiveIsFirst">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">被担保人是否为科技型企业</div>
                        <div class="field">
                            <span name="passiveIsScience" id="passiveIsScience">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">被担保人是否为文化企业</div>
                        <div class="field">
                            <span name="passiveIsLiterature" id="passiveIsLiterature">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">信用等级</div>
                        <div class="field">
                            <span name="creditLevel" id="creditLevel">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">合同担保金额</div>
                        <div class="field">
                            <span name="guaranteeMoney" id="guaranteeMoney">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">担保余额</div>
                        <div class="field">
                            <span name="guaranteeSurplusMoney" id="guaranteeSurplusMoney">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">金融局入库结果</div>
                        <div class="field">
                            <span name="busInfoAsynCode" id="busInfoAsynCode">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">上报批次号</div>
                        <div class="field">
                            <span name="busInfoBatchNum" id="busInfoBatchNum">&nbsp;</span>
                        </div>
                    </div>

                    <div class="caption">
                        <span class="title">担保合同信息</span>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">合同类型</div>
                        <div class="field">
                            <span name="type" id="type">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">合同签订日期</div>
                        <div class="field">
                            <span name="signatureTime" id="signatureTime">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">上报批次号</div>
                        <div class="field">
                            <span name="conInfoBatchNum" id="conInfoBatchNum">&nbsp;</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">金融局入库结果</div>
                        <div class="field">
                            <span name="conInfoAsynCode" id="conInfoAsynCode">&nbsp;</span>
                        </div>
                    </div>

                    <div class="clearFix"></div>
                    <div class="sqPanel">
                        <div class="sqPanel_head inL">
                            <span>业务状态信息</span>
                        </div>
                        <div class="sqPanel_body">
                            <div id="ligergrid_bus_status" class="sq-grid"></div>
                        </div>
                    </div>

                    <div class="clearFix"></div>
                    <div class="sqPanel">
                        <div class="sqPanel_head inL">
                            <span>交易流水</span>
                        </div>
                        <div class="sqPanel_body">
                            <div id="ligergrid_tran_info" class="sq-grid"></div>
                        </div>
                    </div>

                    <div class="fieldBox col_100" style="display:none;">
                        <div class="field">
                            <input name="busSourceId" id="busSourceId" type="text" class="ui-textbox" value="${busSourceId }">
                            <input name="busSource" id="busSource" type="text" class="ui-textbox" value="${busSource }">
                            <input name="busSourceType" id="busSourceType" type="text" class="ui-textbox" value="${busSourceType }">
                        </div>
                    </div>

                    <!-- 按钮 -->
                    <div id="btnsBox" class="btnsBox"></div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    var loadedTabs = [];
    var busStatusGrid;
    var tranInfoGrid;
    var busSourceId = '${busSourceId}';
    var busSource = '${busSource}';
    var busSourceType = '${busSourceType}';

    $(function () {
        initTab();
        initData();

        initBusStatusGrid();
        initTranInfoGrid();

        $("#formSet1").ligerForm();
    });

    function initData() {
        if (!busSourceId) return;
        var _url = '<%=path%>/fgi/fgibusinfo/getSubmitDetailByBusSourceId.do?busSourceId=' + busSourceId + '&busSource=' + busSource + '&busSourceType=' + busSourceType;
        $.ajax({
            type: 'get',
            dataType: 'json',
            //data: {id: id},
            url: _url,
            success: function (msg) {
                if (msg.success == 1) {
                    setData(msg.data);//设置数据
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //设置页面数据
    function setData(data) {
        var form = liger.get("formSet1");

        /*用户信息*/
        if (data.userInfo) { //客户姓名
            $("#userName").html(data.userInfo.userName);
            //用户手机号 掩码展示
            $("#userPhone").html(data.userInfo.userPhone);
            //法人代表
            $("#userLawPerson").html(data.userInfo.userLawPerson);
            //注册资金
            $("#userFund").html(data.userInfo.userFund);
            //注册省份
            $("#userProvince").html(data.userInfo.userProvince);
            //注册地址
            $("#userAddress").html(data.userInfo.userAddress);
            //企业注册时间
            $("#registerDate").html(data.userInfo.registerDate);
            //金融局入库结果
            $("#userInfoAsynCode").html(data.userInfo.asynMessage);
            //上报批次号
            $("#userInfoBatchNum").html(data.userInfo.batchNum);
        }

        /*业务信息*/
        if (data.busInfo) { //担保类型
            if ("1" == data.busInfo.guaranteeType) {
                $("#guaranteeType").html("借款担保（担保人为被担保人贷款、互联网借贷、融资租赁、商业保理、票据承兑、信用证等债务融资提供担保的行为）");
            } else if ("2" == data.busInfo.guaranteeType) {
                $("#guaranteeType").html("债券担保（担保人为被担保人发行债券等债务融资提供担保的行为）");
            } else if ("3" == data.busInfo.guaranteeType) {
                $("#guaranteeType").html("其他担保（担保人为被担保人发行基金产品、信托产品、资产管理计划、资产支持证券等提供担保的行为）");
            } else if ("4" == data.busInfo.guaranteeType) {
                $("#guaranteeType").html("综合消费贷款担保");
            } else if ("5" == data.busInfo.guaranteeType) {
                $("#guaranteeType").html("住房置业贷款担保");
            }
            //融资用途
            $("#financePurpose").html(data.busInfo.financePurpose);
            //担保开始日期
            $("#startTime").html(data.busInfo.startTime);
            //担保到期日期
            $("#endTime").html(data.busInfo.endTime);
            //担保费率
            $("#guaranteeRate").html((data.busInfo.guaranteeRate * 100) + '%');
            //分担比例
            $("#shareProportion").html(data.busInfo.shareProportion);
            //是否农户
            $("#isAgriculture").html(getStatusNm(data.busInfo.isAgriculture));
            //是否为中型企业
            $("#isMediumCompany").html(getStatusNmWirhDefulat(data.busInfo.isMediumCompany));
            //是否为小微企业
            $("#isTinyCompany").html(getStatusNmWirhDefulat(data.busInfo.isTinyCompany))
            //是否为综合服务贷款担保
            $("#isCompositeGuarantees").html(getStatusNmWirhDefulat(data.busInfo.isCompositeGuarantees));
            //是否为住房置业贷款担保
            $("#isHouseGuarantees").html(getStatusNmWirhDefulat(data.busInfo.isHouseGuarantees));
            //是否为互联网借贷担保
            $("#isInternetGuarantees").html(getStatusNmWirhDefulat(data.busInfo.isInternetGuarantees));
            //是否为银行业金融机构表外业务担保
            $("#isBankFinance").html(getStatusNmWirhDefulat(data.busInfo.isBankFinance));
            //被担保人是否为首次获得金融担保
            $("#passiveIsFirst").html(getStatusNmWirhDefulat(data.busInfo.passiveIsFirst));
            //被担保人是否为科技型企业
            $("#passiveIsScience").html(getStatusNmWirhDefulat(data.busInfo.passiveIsScience));
            //被担保人是否为文化企业
            $("#passiveIsLiterature").html(getStatusNmWirhDefulat(data.busInfo.passiveIsLiterature));
            //信用等级
            if (data.busInfo.creditLevel) {
                $("#creditLevel").html(getStatusNm(data.busInfo.creditLevel));
            } else {
                $("#creditLevel").html("未涉及");
            }
            //合同担保金额
            $("#guaranteeMoney").html(data.busInfo.guaranteeMoney);
            //担保余额
            $("#guaranteeSurplusMoney").html(data.busInfo.guaranteeSurplusMoney);
            //金融局入库结果
            $("#busInfoAsynCode").html(data.busInfo.asynMessage);
            //上报批次号
            $("#busInfoBatchNum").html(data.busInfo.batchNum);
        }

        /*担保合同信息*/
        if (data.conInfo) { //合同类型
            $("#type").html(data.conInfo.type);
            if ("1" == data.conInfo.type) {
                $("#guaranteeType").html("担保合同");
            } else if ("2" == data.conInfo.type) {
                $("#guaranteeType").html("保证合同");
            } else if ("3" == data.conInfo.type) {
                $("#guaranteeType").html("其他合同");
            } else if ("4" == data.conInfo.type) {
                $("#guaranteeType").html("公积金合同");
            } else if ("5" == data.conInfo.type) {
                $("#guaranteeType").html("无明确合同合同");
            }
            //合同签订日期
            $("#signatureTime").html(data.conInfo.signatureTime);
            if (data.busInfo) {
                //上报批次号
                $("#conInfoBatchNum").html(data.busInfo.batchNum);
                //金融局入库结果
                $("#conInfoAsynCode").html(data.busInfo.asynMessage);
            }
        }

        //日期处理
        /*var date = new Date(data.regDt);
        var dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);*/
    };

    //初始化业务状态
    function initBusStatusGrid() {
        if (!busSourceId) {
            return; //验证不通过，不执行以下代码
        }
        $("#ligergrid_bus_status").ligerGrid({
            usePager: false,
            url: '<%=path%>/fgi/fgibusstatus/initBusStatusList.do?busSourceId=' + busSourceId + '&busSource=' + busSource + '&busSourceType=' + busSourceType,
            method: 'get',
            columns: [
                {display: '上报时间', name: 'subTm', minWidth: 100,
                    render: function (rowdata, rowindex, value) {
                        return renderDate(rowdata, rowindex, value);
                    }
                },
                {display: '上报状态', name: 'guaranteeStatus', minWidth: 140},
                {display: '状态更新时间', name: 'updateTime', width: 100},
                {display: '金融局入库结果', name: 'asynCode', minWidth: 140,
                    /*render: function (rowdata, rowindex, value) {
                        return getAsynCodeNm(rowdata.asynMessage);
                    }*/
                },
                {
                    display: '上报批号', name: 'batchNum', minWidth: 60
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            isScroll: false,
            //checkbox:true,
            rownumbers: true,
            onAfterShowData: function () {
                SetIframe_height();
            }
        });
        busStatusGrid = liger.get("ligergrid_bus_status");
    };

    //初始化交易流水
    function initTranInfoGrid() {
        var _busSourceId = $("#busSourceId").val();
        if (!_busSourceId) {
            return; //验证不通过，不执行以下代码
        }
        $("#ligergrid_tran_info").ligerGrid({
            usePager: false,
            url: '<%=path%>/fgi/fgitraninfo/initTranInfoList.do?busSourceId=' + busSourceId + '&busSource=' + busSource + '&busSourceType=' + busSourceType,
            method: 'get',
            columns: [
                {display: '上报时间', name: 'subTm', minWidth: 100,
                    render: function (rowdata, rowindex, value) {
                        return renderDate(rowdata, rowindex, value);
                    }
                },
                {display: '交易流水时间', name: 'transTime', minWidth: 140},
                {display: '交易类型', name: 'transType', width: 100,
                    render: function (rowdata, rowindex, value) {
                        if ("1" == rowdata.transType) {
                            return '还款本金';
                        } else if ("2" == rowdata.transType) {
                            return '还款利息';
                        } else if ("3" == rowdata.transType) {
                            return '代偿本金';
                        } else if ("4" == rowdata.transType) {
                            return '代偿利息';
                        } else if ("5" == rowdata.transType) {
                            return '追偿金额';
                        } else if ("6" == rowdata.transType) {
                            return '损失金额';
                        }
                    }
                },
                {display: '交易金额(元)', name: 'transMoney', minWidth: 140},
                {
                    display: '流水编号', name: 'id', minWidth: 60
                },
                {
                    display: '交易金额描述', name: 'transMoneyDec', minWidth: 170, align: 'left'
                },
                {display: '金融局入库结果', name: 'asynMessage', minWidth: 150,
                    /*render: function (rowdata, rowindex, value) {
                        return getAsynCodeNm(rowdata.asynMessage)
                    }*/
                },
                {
                    display: '上报批次号', name: 'batchNum', minWidth: 150
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            isScroll: false,
            //checkbox:true,
            rownumbers: true,
            onAfterShowData: function () {
                SetIframe_height();
            }
        });
        tranInfoGrid = liger.get("ligergrid_tran_info");
    };

    //初始化Tab页
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: 450,
            onBeforeSelectTabItem: function (tabid) {
                var _busSourceId = $("#busSourceId").val();
                if (tabid != "tabA") {
                    if (!_busSourceId) {

                    }
                }
            },
            onAfterSelectTabItem: function (tabid) {
                if (loadedTabs.indexOf(tabusSourceId) < 0) {
                    var _busSourceId = $("#busSourceId").val();
                    if (tabid != "tabA") {
                        if (!_busSourceId) {

                        }
                    }
                    loadedTabs.push(tabid);
                    switch (tabid) {
                        case "tabB":
                            pageInTab.setTabItemSrc(tabid, "");
                            break;
                    }
                }
                ;
                SetIframe_height();
            }
        });
    };

    //获取状态名称
    function getStatusNm(status) {
        if ("1" == status) {
            return "是";
        } else if ("0" == status) {
            return "否";
        } else if ("-1" == status) {
            return "未涉及";
        }
    }

    //获取状态名称 , 默认为'否'
    function getStatusNmWirhDefulat(status) {
        if ("1" == status) {
            return "是";
        } else if ("0" == status) {
            return "否";
        } else if ("-1" == status) {
            return "未涉及";
        } else {
            return "否";
        }
    }

    //获取入库结果名称
    function getAsynCodeNm(asynMessage) {
        if ("success" == asynMessage) {
            $("#userInfoAsynCode").html("入库成功");
        } else if ("hold" == asynMessage) {
            $("#userInfoAsynCode").html("等待处理");
        } else if ("failed" == asynMessage) {
            $("#userInfoAsynCode").html("入库失败");
        } else if ("isNot" == asynMessage) {
            $("#userInfoAsynCode").html("批次号无效");
        } else {
            $("#userInfoAsynCode").html("批次号无效");
        }
    }

    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
</script>
</body>
</html>